from aiogram_dialog import DialogManager
from fluentogram import TranslatorRunner

from poker_bot.database.services import AccountService, DepositService, UserService


async def user_deposits_getter(
    dialog_manager: DialogManager, deposit_service: DepositService, **kwargs
):
    user_deposits = await deposit_service.get_user_deposits(
        dialog_manager.event.from_user.id
    )

    return {"user_deposits": user_deposits}


async def all_deposits_getter(
    dialog_manager: DialogManager, deposit_service: DepositService, **kwargs
):
    all_deposits = await deposit_service.get_all_deposits()

    return {"all_deposits": all_deposits}


async def unconfirmed_deposits_getter(
    dialog_manager: DialogManager, deposit_service: DepositService, **kwargs
):
    unconfirmed_deposits = await deposit_service.get_deposits_for_confirmation()

    return {"unconfirmed_deposits": unconfirmed_deposits}


async def deposit_info_getter(
    dialog_manager: DialogManager,
    locale: TranslatorRunner,
    deposit_service: DepositService,
    user_service: UserService,
    account_service: AccountService,
    **kwargs
):
    deposit_id: int = dialog_manager.dialog_data.get("deposit_id")

    deposit = await deposit_service.get_deposit_by_id(deposit_id)
    user = await user_service.get_user_by_id(deposit.user_id)
    account = await account_service.get_account_by_id(user.selected_account_id)

    return {
        "deposit_id": deposit.id,
        "account_id": account.account_id,
        "status": deposit.status,
        "summ": deposit.summ,
        "username": user.username,
        "user_tg_id": user.telegram_id,
        "currency_symbol": deposit.currency_symbol,
        "status_value": locale.get(deposit.status.name),
        "was_created": deposit.created_at,
    }
